package com.etcn.modules.busi.member.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.etcn.common.annotation.Manage;
import com.etcn.common.controller.BaseController;
import com.etcn.common.pojo.FileUploadVo;
import com.etcn.modules.busi.member.pojo.WmMember;
import com.etcn.modules.busi.member.service.IWmMemberService;

/**
 * 会员controller
 * @author guozc
 * @date: 2018-03-09 08:21:55
 */
@RestController
@RequestMapping("/v1/member")
public class WmMemberController extends BaseController {

	@Autowired
    private IWmMemberService wmMemberService;
	
    /**
     * 注册
     */
    @Manage
    @RequestMapping(value = "register", method = RequestMethod.POST)
    public Object register(@RequestBody WmMember wmMember) throws Exception{
    	return wmMemberService.register(wmMember);
    }
    
    /**
     * 登录
     */
    @Manage
    @RequestMapping(value = "login", method = RequestMethod.POST)
    public Object login(@RequestBody WmMember wmMember) throws Exception{
    	return wmMemberService.login(wmMember);
    }

    /**
     * 短信登录
     */
    @Manage
    @RequestMapping(value = "smslogin", method = RequestMethod.POST)
    public Object smslogin(@RequestBody WmMember wmMember) throws Exception{
        return wmMemberService.loginWithSms(wmMember);
    }
    
    /**
     * 退出登录
     */
    @Manage
    @RequestMapping(value = "logout", method = RequestMethod.POST)
    public void logout() throws Exception{
    	wmMemberService.logout();
    }

    /**
     * 查询会员详情
     */
    @Manage
    @RequestMapping(value = "{memberId}", method = RequestMethod.GET)
    public Object getDetail(@PathVariable("memberId") String memberId) throws Exception{
    	return wmMemberService.getDetail(memberId);
    } 
    
    /**
     * 上传头像
     */
    @Manage
    @RequestMapping(value = "uploadavatar", method = RequestMethod.POST)
    public Object uploadAvatar(@ModelAttribute FileUploadVo fileUploadVo) throws Exception{
    	return wmMemberService.uploadAvatar(fileUploadVo);
    }
    
    /**
     * 修改资料
     */
    @Manage
    @RequestMapping(value = "changeprofile", method = RequestMethod.POST)
    public Object changeProfile(@RequestBody WmMember member) throws Exception{
    	return wmMemberService.updateByMemberId(member);
    }
    
    /**
     * 修改密码
     */
    @Manage
    @RequestMapping(value = "changepwd", method = RequestMethod.POST)
    public void changePwd(@RequestBody WmMember member) throws Exception{
    	wmMemberService.changePwd(member);
    }
    
    /**
     * 忘记密码
     */
    @Manage
    @RequestMapping(value = "forgotpwd", method = RequestMethod.POST)
    public void forgotPwd(@RequestBody WmMember member) throws Exception{
    	wmMemberService.forgotPwd(member);
    }
    
    /**
     * 发送注册短信验证码
     */
    @Manage
    @RequestMapping(value = "sendregistersms", method = RequestMethod.POST)
    public void sendRegisterSms(@RequestBody WmMember member) throws Exception{
    	wmMemberService.sendRegisterSms(member);
    }

    /**
     * 发送短信验证码
     */
    @Manage
    @RequestMapping(value = "sendsms", method = RequestMethod.POST)
    public void sendsms(@RequestBody WmMember member) throws Exception{
        wmMemberService.sendsms(member);
    }
    
}